<template>
  <h1>员工列表综合练习</h1>
  <el-form style="width:600px;margin: 0 auto;">
    <el-form-item label="姓名">
      <el-input v-model="emp.name" placeholder="请输入姓名"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input v-model="emp.salary" placeholder="请输入工资"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input v-model="emp.job" placeholder="请输入岗位"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="add()">点我提交</el-button>
    </el-form-item>
  </el-form>

  <el-table :data="arr" style="width:600px;margin: 0 auto;">
    <el-table-column label="编号" type="index" width="80"></el-table-column>
    <el-table-column label="姓名" prop="name"></el-table-column>
    <el-table-column label="工资" prop="salary"></el-table-column>
    <el-table-column label="岗位" prop="job"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

  <hr>
  <el-table :data="arr" style="width:600px;margin: 0 auto;">
<!--    <el-table-column label="编号" type="index" width="80"></el-table-column>-->
<!--    <el-table-column label="姓名" prop="name"></el-table-column>-->
<!--    <el-table-column label="工资" prop="salary"></el-table-column>-->
<!--    <el-table-column label="岗位" prop="job"></el-table-column>-->
    <el-table-column v-for="col in tableColumns" v-bind="col"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
const emp = ref({name:'',salary:'',job:''});
const arr = ref([]);

const add = ()=>{
  arr.value.push({...emp.value})
}
const del = (i,emp)=>{
  if(confirm('您确认要删除'+emp.name+'吗?')){
    arr.value.splice(i,1);
  }
}

const tableColumns = ref([
  {type:'index',label:'编号',width:80},
  {label:'姓名',prop:'name'},
  {label:'工资',prop:'salary'},
  {label:'岗位',prop:'job'}
]);
</script>

<style scoped>

</style>